Passed
Push — depfu/update/npm/lodash-4.17.1... ( 152c97 )
by
unknown
04:58
created

SelectMapFullComponent   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 55
dl 0
loc 67
rs 10
c 0
b 0
f 0
wmc 3

2 Functions

Rating   Name   Duplication   Size   Complexity  
A ngOnInit 0 2 1
A trackByFn 0 3 2
1
import { GameDataService } from './../../data/gameData.service';
2
import { ValueAccessorBase } from './../abstract/ValueAccessorBase';
3
/**
4
   Copyright 2018 June Hanabi
5
6
   Licensed under the Apache License, Version 2.0 (the "License");
7
   you may not use this file except in compliance with the License.
8
   You may obtain a copy of the License at
9
10
       http://www.apache.org/licenses/LICENSE-2.0
11
12
   Unless required by applicable law or agreed to in writing, software
13
   distributed under the License is distributed on an "AS IS" BASIS,
14
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
   See the License for the specific language governing permissions and
16
   limitations under the License.
17
 */
18
19
declare var window: {
20
    require: any;
21
}
22
23
import { Component, OnInit, Input } from '@angular/core';
24
25
import {
26
    NG_VALUE_ACCESSOR,
27
} from '@angular/forms';
28
import { Map } from '../../../assets/data/maps.d';
29
30
const _: any = window.require("lodash");
31
32
@Component({
33
    selector: 'select-map-full',
34
    templateUrl: './select-map-full.component.pug',
35
    styleUrls: ['./select-map-full.component.scss'],
36
    providers: [
37
        { provide: NG_VALUE_ACCESSOR, useExisting: SelectMapFullComponent, multi: true }
38
    ],
39
})
40
export class SelectMapFullComponent extends ValueAccessorBase<string> implements OnInit {
41
42
    constructor(
43
        public gd: GameDataService
44
    ) {
45
        super();
46
    }
47
48
    ngOnInit() {
49
50
    }
51
52
    @Input()
53
    public disabled: boolean = false;
54
55
    @Input()
56
    public noneSelectable: boolean = false;
57
58
    @Input()
59
    public label: string = "Select Map";
60
61
    get mapList() {
62
        const maps: Map[] = this.gd.file("maps").data;
63
64
        const b = (val: number | any) => {
65
            return val.toString(16).padStart(2, "0").toUpperCase();
66
        }
67
68
        const w = (val: number | any) => {
69
            return val.toString(16).padStart(4, "0").toUpperCase();
70
        }
71
72
        const a = (val: number | any) => {
73
            return val.toString().padStart(2, "0");
74
        }
75
76
        let _maps: {
77
            name: string,
78
            value: string
79
        }[] = [];
80
81
        maps.forEach((el: Map) => {
82
            if (el.glitch === true || el.special === true)
83
                return;
84
85
            _maps.push({
86
                name: el.name,
87
                value: `${b(el.ind)}_${a(el.height)}_${a(el.width)}_${a(el.height2x2)}_${a(el.width2x2)}_${w(el.dataPtr)}_${w(el.textPtr)}_${w(el.scriptPtr)}`,
88
            });
89
        });
90
91
        _maps = _.sortBy(_maps, ['name']);
92
93
        return _maps;
94
    }
95
96
    trackByFn(index: number) {
97
        return index;
98
    }
99
}
100